package com.block.account.service.impl;

import com.block.account.model.dto.ChangeAmountDTO;
import com.block.db.entity.AccountMerchantInfoHis;
import com.block.db.entity.AccountProductInfo;
import com.block.db.entity.AccountProductInfoHis;
import com.block.db.mapper.AccountProductInfoHisMapper;
import com.block.account.service.IAccountProductInfoHisService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDate;

/**
 * <p>
 * 渠道账户流水 服务实现类
 * </p>
 *
 * @author 
 * @since 2023-08-26
 */
@Service
public class AccountProductInfoHisServiceImpl extends ServiceImpl<AccountProductInfoHisMapper, AccountProductInfoHis> implements IAccountProductInfoHisService {

    @Override
    public boolean saveAccountHis(BigDecimal currentAmount, AccountProductInfo accountProductInfo, ChangeAmountDTO changeAmountDTO) {

        AccountProductInfoHis productInfoHis = new AccountProductInfoHis();
        productInfoHis.setAccountId(accountProductInfo.getProductId());
        productInfoHis.setAccountName(changeAmountDTO.getAccountName());
        productInfoHis.setDateInfo(LocalDate.now().toString());
        productInfoHis.setBillDateInfo(changeAmountDTO.getBillDateInfo());
        productInfoHis.setActionType(changeAmountDTO.getActionTypeEnum().getValue());
        productInfoHis.setCurrentAmount(currentAmount);
        productInfoHis.setOriginAmount(accountProductInfo.getTotalAmount());
        productInfoHis.setChangeAmount(changeAmountDTO.getChangeAmount());
        productInfoHis.setDataInfo(changeAmountDTO.getDataInfo());
        productInfoHis.setRemarkInfo(changeAmountDTO.getRemarkInfo());
        productInfoHis.setOpertorId(changeAmountDTO.getOperatorId());
        productInfoHis.setOpertorName(changeAmountDTO.getOperatorName());

        boolean save = this.save(productInfoHis);

        return save;
    }
}
